package cn.tedu.self;

import java.util.Arrays;
import java.util.Random;


public class BubbleSort {
    public static void main(String[] args) {
        int[] a=new int[5];
        for(int i=0;i<=4;i++){
            a[i]=new Random().nextInt(100);
        }
        System.out.println(Arrays.toString(a));
        int[] newa= bubble(a);
        System.out.println("最终排序后"+Arrays.toString(newa));

    }

    private static int[] bubble(int[] a) {
        for(int i=0;i<=a.length-1;i++){
            System.out.println("第"+i+"轮");
            for(int j=0;j<a.length-1-i;j++){
                if(a[j]>a[j+1]){
                    int t=a[j];
                    a[j]=a[j+1];
                    a[j+1]=t;
                }
            }
            System.out.println(Arrays.toString(a));
        }
        return a;
    }
}
